#include <cstdio>
#include <SFML/Graphics.hpp>
#include "../../common.h"

using namespace std;
using namespace sf;

char name[100];
string def_name;

string gen_name()
{
   string img_n(name);
   string def_n("");
   
   for(int i = 0 ; i < img_n.size() ; i++)
   {
      if(img_n[i] == '.')
         break;
      def_n += img_n[i];
   }
   
   return def_n;
}

int main()
{
   printf("Tileset name : ");
   scanf("%s", name);
   
   def_name = gen_name();
   def_name += ".tsdef";
   
   FILE *def_file = fopen(def_name.c_str(), "r+");
   
   Image img;
   img.LoadFromFile(name);
   
   int height = img.GetHeight()/TILE_DIM;
   int width = img.GetWidth()/TILE_DIM;
   
   fprintf(def_file, "%d %d\n", height, width);
   
   int curr = 0;
   
   for(int iLig = 0 ; iLig < height ; iLig++)
   {
      for(int iCol = 0 ; iCol < width ; iCol++)
      {
         fprintf(def_file, "%d ", curr);
         curr++;
      }
      fprintf(def_file, "\n");
   }
   
   fclose(def_file);
}
